package clientGUI.user.ISD;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JComboBox;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.JTextPane;
import javax.swing.JButton;

import clientGUI.user.Controllers.ISD.ISDRequestController;
import clientGUI.userPanels.UPanel;
import clientGUI.userPanels.Controllers.RequestController;
import clientserver.Client;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ISDRequestWatch extends UPanel {
	private JTextPane infoPane;
	private JComboBox ridCB;
	private ISDRequestController controller;

	/**
	 * Create the panel.
	 */
	public ISDRequestWatch(Client connectedcl) {
		client=connectedcl;
		controller= new ISDRequestController(client);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblRequestId = new JLabel("Request ID:");
		GridBagConstraints gbc_lblRequestId = new GridBagConstraints();
		gbc_lblRequestId.insets = new Insets(0, 0, 5, 5);
		gbc_lblRequestId.anchor = GridBagConstraints.EAST;
		gbc_lblRequestId.gridx = 4;
		gbc_lblRequestId.gridy = 1;
		add(lblRequestId, gbc_lblRequestId);
		ArrayList<String> rids=controller.getallrids();
		ridCB = new JComboBox(rids.toArray());
		GridBagConstraints gbc_ridCB = new GridBagConstraints();
		gbc_ridCB.insets = new Insets(0, 0, 5, 0);
		gbc_ridCB.fill = GridBagConstraints.HORIZONTAL;
		gbc_ridCB.gridx = 5;
		gbc_ridCB.gridy = 1;
		add(ridCB, gbc_ridCB);
		
		JButton btnShowInfo = new JButton("Show Info");
		btnShowInfo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			
			{
			   String id=(String) ridCB.getSelectedItem();	
			   String   report=controller.getReport(id);
			   infoPane.setText(report);
				
			}
		});
		GridBagConstraints gbc_btnShowInfo = new GridBagConstraints();
		gbc_btnShowInfo.insets = new Insets(0, 0, 5, 0);
		gbc_btnShowInfo.gridx = 5;
		gbc_btnShowInfo.gridy = 2;
		add(btnShowInfo, gbc_btnShowInfo);
		
		infoPane = new JTextPane();
		GridBagConstraints gbc_infoPane = new GridBagConstraints();
		gbc_infoPane.gridwidth = 3;
		gbc_infoPane.fill = GridBagConstraints.BOTH;
		gbc_infoPane.gridx = 3;
		gbc_infoPane.gridy = 3;
		add(infoPane, gbc_infoPane);
setName(" Requests in system");


	}

}
